import React from 'react'

import { Form, Input, InputNumber, Select, Button, Upload, message } from 'antd'
import { UploadOutlined } from '@ant-design/icons'
import request from '@/utils/request'

export default (props: any) => {
    const { close } = props

    const handleUploadChange = (info: any): any => {
        let fileList = info.fileList;
        fileList = fileList.slice(-1);
        if (info.file.status === 'done') {
            message.success(`${info.file.name}文件上传成功`);
            fileList[0].url = fileList[0]['response']['data']['filePath'];
        }
        return fileList
    }

    const onSubmit = (values: any) => {

        if (values.upload && values.upload.length > 0) {
            values.logo = values.upload[0]['url'];
        }
    }

    return (
        <Form
            labelCol={{ span: 3 }}
            wrapperCol={{ span: 19 }}
            onFinish={onSubmit}
        >
            <Form.Item label="物流公司名称" required>
                <Input style={{ width: "40%" }} />
            </Form.Item>
            <Form.Item label="物流公司LOGO" name="upload" valuePropName="fileList" getValueFromEvent={handleUploadChange}>
                <Upload
                    action='http://127.0.0.1:8888/admin/tool/upload'
                    listType='picture'
                >
                    <Button>
                        <UploadOutlined /> Upload
                        </Button>
                </Upload>
            </Form.Item>
            <Form.Item label="排序">
                <InputNumber />
            </Form.Item>
            <Form.Item label="url地址" required help="请输入物流公司官方网址">
                <Input />
            </Form.Item>
            <Form.Item label="菜鸟物流接口编码">
                <Input />
            </Form.Item>
            <Form.Item label="快递查询接口编码">
                <Input />
            </Form.Item>
            <Form.Item label="快递100免费版编码">
                <Input />
            </Form.Item>
            <Form.Item label="快递100付费版编码">
                <Input />
            </Form.Item>
            <Form.Item wrapperCol={{ offset: 3 }}>
                <Button type="primary" style={{ marginRight: "6px" }}>保存</Button>
                <Button onClick={() => close()}>取消</Button>
            </Form.Item>
        </Form>
    )
}